<!DOCTYPE HTML>
<html lang="en">
<head>
<title>FileEncoding - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The FileEncoding command sets the default encoding for FileRead, FileReadLine, Loop Read, FileAppend, and FileOpen()." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>FileEncoding <span class="ver">[AHK_L 42+]</span></h1>

<p>Sets the default encoding for <a href="FileRead.htm">FileRead</a>, <a href="FileReadLine.htm">FileReadLine</a>, <a href="LoopReadFile.htm">Loop Read</a>, <a href="FileAppend.htm">FileAppend</a>, and <a href="FileOpen.htm">FileOpen()</a>.</p>

<pre class="Syntax"><span class="func">FileEncoding</span> <span class="optional">, Encoding</span></pre>

<h2>Parameters</h2>
<dl>
  <dt>Encoding</dt>
  <dd>
    <p>One of the following values (if omitted, it defaults to the system default ANSI code page, which is also the default setting):</p>
    <p><strong>UTF-8:</strong> Unicode UTF-8, equivalent to CP65001.</p>
    <p><strong>UTF-8-RAW:</strong> As above, but no byte order mark is written when a new file is created.</p>
    <p><strong>UTF-16:</strong> Unicode UTF-16 with little endian byte order, equivalent to CP1200.</p>
    <p><strong>UTF-16-RAW:</strong> As above, but no byte order mark is written when a new file is created.</p>
    <p><strong>CP<em>nnn</em>:</strong> A code page with numeric identifier <em>nnn</em>. See <a href="http://msdn.microsoft.com/en-us/library/dd317756.aspx">Code Page Identifiers</a>.</p>
  </dd>
</dl>

<h2>Remarks</h2>
<p><code>A_FileEncoding</code> contains the current setting.</p>
<p>Every newly launched <a href="../misc/Threads.htm">thread</a> (such as a <a href="../Hotkeys.htm">hotkey</a>, <a href="Menu.htm">custom menu item</a>, or <a href="SetTimer.htm">timed</a> subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).</p>
<p>The default encoding is not used if a UTF-8 or UTF-16 byte order mark is present in the file, unless the file is being opened with write-only access (i.e. the previous contents of the file are being discarded).</p>

<h2>Related</h2>
<p><a href="FileOpen.htm">FileOpen()</a>, <a href="StrGet.htm">StrGet()</a>, <a href="StrPut.htm">StrPut()</a>, <a href="../Compat.htm#FileRead">Script Compatibility</a></p>

</body>
</html>
